import java.util.HashSet;
import java.util.Set;

/*
 * 滑动窗口-最长无重复子串
 * */
public class SlidingWindow {
    public static void main(String[] args) {
        String test = "pwwkew";
        System.out.println(deal(test));
    }

    public static int deal(String word) {
        int max = 0;
        int right = 0;
        int left = 0;
        while (right <= word.toCharArray().length) {
            String sub = word.substring(left, right);
            if (!isRepeat(sub)) {
                max = Math.max(max, sub.length());
                right++;
                continue;
            }
            left++;
        }
        return max;
    }

    public static boolean isRepeat(String word) {
        char[] chars = word.toCharArray();
        Set<Character> set = new HashSet<>();
        for (Character character : chars) {
            set.add(character);
        }
        return set.size() != chars.length;
    }
}